using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using GonzalesCore.CoreElements;
using GonzalesCore.CoreManagers;
using Kypris2.CoreElements;
using Kypris2.Utils;
using Jamila2.Tools;

public partial class GonzalesAdminExpenseCompanyListing : System.Web.UI.Page
{
    protected PrivateLoginSession CurrentPrivateSession = null;
    protected LogManager CurLogManager = null;
    protected readonly int TotalColumns = 6;
    protected DataObj CurPageDataObj = new DataObj();

    #region ResultTable
    protected DataTable ResultTable
    {
        get
        {
            return (DataTable)ViewState["ResultTable"];
        }

        set
        {
            ViewState["ResultTable"] = value;
        }
    }
    #endregion

    #region InvalidMessage
    protected string InvalidMessage
    {
        get
        {
            return ViewState["InvalidMessage"].ToString();
        }

        set
        {
            ViewState["InvalidMessage"] = value;
        }
    }
    #endregion

    #region ConfirmedMessage
    protected string ConfirmedMessage
    {
        get
        {
            return ViewState["ConfirmedMessage"].ToString();
        }

        set
        {
            ViewState["ConfirmedMessage"] = value;
        }
    }
    #endregion

    #region MandatoryField
    protected string MandatoryField
    {
        get
        {
            return ViewState["MandatoryField"].ToString();
        }

        set
        {
            ViewState["MandatoryField"] = value;
        }
    }
    #endregion

    #region Updatedsuccesfully
    protected string Updatedsuccesfully
    {
        get
        {
            return ViewState["Updatedsuccesfully"].ToString();
        }

        set
        {
            ViewState["Updatedsuccesfully"] = value;
        }
    }
    #endregion

    #region ErrorMessage
    protected string ErrorMessage
    {
        get
        {
            return ViewState["ErrorMessage"].ToString();
        }

        set
        {
            ViewState["ErrorMessage"] = value;
        }
    }
    #endregion

    #region Code1
    protected string Code1
    {
        get
        {
            return ViewState["Code1"].ToString();
        }

        set
        {
            ViewState["Code1"] = value;
        }
    }
    #endregion

    #region ExpenseName
    protected string ExpenseName
    {
        get
        {
            return ViewState["ExpenseName"].ToString();
        }

        set
        {
            ViewState["ExpenseName"] = value;
        }
    }
    #endregion

    #region Category
    protected string Category
    {
        get
        {
            return ViewState["Category"].ToString();
        }

        set
        {
            ViewState["Category"] = value;
        }
    }
    #endregion

    #region DeleteLink
    protected string DeleteLink
    {
        get
        {
            return ViewState["DeleteLink"].ToString();
        }

        set
        {
            ViewState["DeleteLink"] = value;
        }
    }
    #endregion

    #region Events

    #region Page_Load
    protected void Page_Load(object sender, EventArgs e)
    {
        this.SessionCheck();

        this.Table_MessageBox.Visible = false;

        // This action is needed only at the first load
        if (!IsPostBack)
        {
            //FRANK: set readonly for Financial Admin
            if (this.CurrentPrivateSession.CurrentLoggedOnUser.IsFinanceAdmin)
                if (!this.CurrentPrivateSession.CurrentLoggedOnUser.IsFinancialManager)
                {
                    Button_Update.Visible = false;
                    Button_Submit.Visible = false;
                }

            // load header
            this.LoadData();

            // Page Componenegt
            this.PageComponentSetup();

            // Language
            this.SwitchLanguage();
        }

        // build table must be done on every load
        this.BuildTable();
        if (this.ResultTable != null)
        {
            DataRow[] ResultRows = this.ResultTable.Select("", this.DropDownList_SortBy.SelectedValue);

            foreach (DataRow ResultRow in ResultRows)
            {
                this.BuildRow(ResultRow);
            }
        }

        // only for the first time
        if (!IsPostBack)
        {
            this.LoadDataBasedOnEntity();
        }
    }
    #endregion

    #region DropDownList_SortBy_SelectedIndexChanged
    protected void DropDownList_SortBy_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (this.DropDownList_SortBy.SelectedIndex == 0)
        {
            // by code
            for (int x = (this.Table_ClaimDetailGrid.Rows.Count - 1); x > 1; x--)
            {
                for (int y = 1; y < x; y++)
                {
                    string Order1 = this.Table_ClaimDetailGrid.Rows[y].Cells[1].Text;
                    string Order2 = this.Table_ClaimDetailGrid.Rows[y + 1].Cells[1].Text;

                    if (Order1.CompareTo(Order2) > 0)
                    {
                        TableRow Tmp1 = this.Table_ClaimDetailGrid.Rows[y];

                        this.Table_ClaimDetailGrid.Rows.RemoveAt(y);
                        this.Table_ClaimDetailGrid.Rows.AddAt(y + 1, Tmp1);
                    }
                }
            }
        }
        else if (this.DropDownList_SortBy.SelectedIndex == 1)
        {
            // by name
            for (int x = (this.Table_ClaimDetailGrid.Rows.Count - 1); x > 1; x--)
            {
                for (int y = 1; y < x; y++)
                {
                    string Order1 = this.Table_ClaimDetailGrid.Rows[y].Cells[2].Text;
                    string Order2 = this.Table_ClaimDetailGrid.Rows[y + 1].Cells[2].Text;

                    if (Order1.CompareTo(Order2) > 0)
                    {
                        TableRow Tmp1 = this.Table_ClaimDetailGrid.Rows[y];

                        this.Table_ClaimDetailGrid.Rows.RemoveAt(y);
                        this.Table_ClaimDetailGrid.Rows.AddAt(y + 1, Tmp1);
                    }
                }
            }
        }        
    }
    #endregion    

    #region DropDownList_ByEntity_SelectedIndexChanged
    protected void DropDownList_ByEntity_SelectedIndexChanged(object sender, EventArgs e)
    {
        for (int x = 1; x < this.Table_ClaimDetailGrid.Rows.Count; x++)
        {
            ((CheckBox)this.Table_ClaimDetailGrid.Rows[x].Cells[0].Controls[0]).Checked = false;
        }

        if (this.DropDownList_ByEntity.SelectedValue.Length > 0)
        {
            this.LoadDataBasedOnEntity();
        }
    }
    #endregion

    #region Button_Update_Click
    protected void Button_Update_Click(object sender, EventArgs e)
    {
        GLClaimTypes SelectedClaimTypes = new GLClaimTypes();
        bool valid = true;

        for (int x = 1; x < this.Table_ClaimDetailGrid.Rows.Count; x++)
        {
            this.Table_ClaimDetailGrid.Rows[x].Cells[4].CssClass = "GridViewItem";
            CheckBox CurCheckBox = (CheckBox)this.Table_ClaimDetailGrid.Rows[x].Cells[0].Controls[0];
            CheckBox CurCheckBoxPerDiem = (CheckBox)this.Table_ClaimDetailGrid.Rows[x].Cells[5].Controls[0];

            if (CurCheckBox.Checked)
            {                
                DropDownList DropDownList_Category = (DropDownList)this.Table_ClaimDetailGrid.Rows[x].Cells[3].Controls[0];
                if (DropDownList_Category.SelectedIndex == 0)
                {
                    this.Table_ClaimDetailGrid.Rows[x].Cells[3].CssClass = "ValidatedErrorComponent";
                    valid = false;
                }
                else
                {
                    GLClaimType CurGLClaimType = new GLClaimType(this.Table_ClaimDetailGrid.Rows[x].ID, "", "");
                    CurGLClaimType.Category = ClaimManager.GetClaimCategoryFromCode(DropDownList_Category.SelectedValue);
                    CurGLClaimType.PerDiem = CurCheckBoxPerDiem.Checked;
                    SelectedClaimTypes.Add(CurGLClaimType);
                }
            }
        }

        if (valid)
        {
            using (GLClaimTypeManager CurClaimTypeManager = new GLClaimTypeManager(this.CurrentPrivateSession))
            {
                if (CurClaimTypeManager.UpdateClaimTypeRelation(SelectedClaimTypes, this.DropDownList_ByEntity.SelectedValue))
                {
                    // log down the history
                    this.CurLogManager.LogMessage("[GonzalesAdminExpenseCompanyListing] : Expense detail updated based on entity (" + this.DropDownList_ByEntity.SelectedValue + ")", this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.User);

                    this.ShowMessage(this.Updatedsuccesfully);
                }
                else
                {
                    string LogID = SwissArmy.UniqueID();
                    this.CurLogManager.LogError(LogID, "[GonzalesAdminExpenseCompanyListing.Button_Update_Click] : Failed at CurClaimTypeManager.UpdateClaimTypeRelation : " + CurClaimTypeManager.ErrorMessage, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.System);
                    this.ShowErrorMessage(this.ErrorMessage + LogID);
                }
            }
        }
        else
        {
            this.ShowErrorMessage(this.MandatoryField);
        }
    }
    #endregion

    #region Button_Submit_Click
    protected void Button_Submit_Click(object sender, EventArgs e)
    {
        if (this.DataSave())
        {

            // log down the history
            this.CurLogManager.LogMessage("[GonzalesAdminExpenseCompanyListing] : New Expense (" + this.DropDownList_ByEntity.SelectedValue + ", " + this.TextBox_Code.Text +  ", " + this.TextBox_Description.Text +  ") detail added", this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.User);

            this.ShowMessage(this.Updatedsuccesfully);

            this.LoadData();

            this.Table_ClaimDetailGrid.Rows.Clear();

            this.BuildTable();
            if (this.ResultTable != null)
            {
                DataRow[] ResultRows = this.ResultTable.Select("", this.DropDownList_SortBy.SelectedValue);

                foreach (DataRow ResultRow in ResultRows)
                {
                    this.BuildRow(ResultRow);
                }
            }

            this.LoadDataBasedOnEntity();

        }
    }
    #endregion

    #region LinkButtonDelete_Click
    void LinkButtonDelete_Click(object sender, EventArgs e)
    {
        string RowID = ((LinkButton)sender).ID.Substring(0, 36);

        using (GLClaimTypeManager CurManager = new GLClaimTypeManager(this.CurrentPrivateSession))
        {
            if (CurManager.DeleteClaimTypeByID(RowID))
            {
                for (int x = 1; x < this.Table_ClaimDetailGrid.Rows.Count; x++)
                {
                    if (this.Table_ClaimDetailGrid.Rows[x].ID.CompareTo(RowID) == 0)
                    {
                        this.Table_ClaimDetailGrid.Rows.RemoveAt(x);
                        break;
                    }
                }
            }
            else
            {
                string LogID = SwissArmy.UniqueID();
                this.CurLogManager.LogError(LogID, "[GonzalesAdminExpenseCompanyListing.LinkButtonDelete_Click] : Failed at CurManager.DeleteClaimTypeByID('" + RowID + "') : " + CurManager.ErrorMessage, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.System);
                this.ShowErrorMessage(this.ErrorMessage + LogID);
            }
        }
    }
    #endregion

    #endregion

    #region Customized Methods

    #region SessionCheck
    public void SessionCheck()
    {

        if (Session[GonzalesCommonNamingConvention.CurrentPrivateSession] != null)
        {
            this.CurrentPrivateSession = (PrivateLoginSession)Session[GonzalesCommonNamingConvention.CurrentPrivateSession];
            this.CurLogManager = new LogManager(this.CurrentPrivateSession);    // activate Log Manager
        }
        else
        {
            Response.Redirect(GonzalesErrorPageRedirect.SessionError);
        }

    }
    #endregion

    #region PageComponentSetup
    protected void PageComponentSetup()
    {
        // setup entity
        if (this.CurrentPrivateSession.CurrentLoggedOnUser.IsPowerAdmin)
        {
            #region Power Admin
            using (EntityManager CurEntityManager = new EntityManager(this.CurrentPrivateSession))
            {
                MasterBaseCollection ResultList = CurEntityManager.GetAllEntity();
                if (ResultList != null)
                {
                    this.DropDownList_ByEntity.Items.Add(new ListItem("", ""));
                    for (int x = 0; x < ResultList.Count; x++)
                    {
                        this.DropDownList_ByEntity.Items.Add(new ListItem(ResultList[x].DisplayName, ResultList[x].InternalID));
                    }
                }
                else
                {
                    // display error
                    this.CurLogManager.LogError("[GonzalesAdminClaimantsListing.PageComponentSetup] : Failed on CurEntityManager.GetAllEntity() : " + CurEntityManager.ErrorMessage, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.System);

                }
            }
            #endregion
        }
        else
        {
            #region Finance Admin

            using (UserManager CurManager = new UserManager(this.CurrentPrivateSession))
            {
                MasterBaseCollection ResultList = CurManager.GetEntityByFinanceAdmin(this.CurrentPrivateSession.CurrentLoggedOnUser.InternalID);
                if (ResultList != null)
                {
                    for (int x = 0; x < ResultList.Count; x++)
                    {
                        this.DropDownList_ByEntity.Items.Add(new ListItem(ResultList[x].DisplayName, ResultList[x].InternalID));
                    }
                }
                else
                {
                    // display error
                    this.CurLogManager.LogError("[GonzalesAdminClaimantsListing.PageComponentSetup] : Failed on CurEntityManager.GetAllEntity() : " + CurManager.ErrorMessage, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.System);
                }
            }

            this.DropDownList_ByEntity_SelectedIndexChanged(null, null);

            #endregion
        }
        
    }
    #endregion

    #region SwitchLanguage
    protected void SwitchLanguage()
    {
        try
        {
            using (MultiLingualFactory CurLanguageFactory = MultiLingualEngine.GetMultiLingualFactory(this, this.CurrentPrivateSession.CurrentLoggedOnUser.PreferedLanguage.InternalID))
            {
                this.Label_Code.Text = CurLanguageFactory.DisplayValue("Code");
                this.Label_Customize.Text = CurLanguageFactory.DisplayValue("Customize");
                this.Label_Description.Text = CurLanguageFactory.DisplayValue("Description");
                this.Label_Information.Text = CurLanguageFactory.DisplayValue("Information");
                this.Label_PageTitle.Text = CurLanguageFactory.DisplayValue("PageTitle");
                this.Button_Submit.Text = CurLanguageFactory.DisplayValue("Submit");
                this.Button_Update.Text = CurLanguageFactory.DisplayValue("Update");
                this.InvalidMessage = CurLanguageFactory.DisplayValue("InvalidMessage");
                this.ErrorMessage = CurLanguageFactory.DisplayValue("ErrorMessage");
                this.MandatoryField = CurLanguageFactory.DisplayValue("MandatoryField");
                this.Updatedsuccesfully = CurLanguageFactory.DisplayValue("Updatedsuccesfully");
                this.ConfirmedMessage = CurLanguageFactory.DisplayValue("ConfirmedMessage");
                this.Code1 = CurLanguageFactory.DisplayValue("Code1");
                this.ExpenseName = CurLanguageFactory.DisplayValue("ExpenseName");
                this.DeleteLink = CurLanguageFactory.DisplayValue("DeleteLink");
                this.Category = CurLanguageFactory.DisplayValue("Category");


                this.DropDownList_SortBy.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("Code1"), this.CurPageDataObj.Code));
                this.DropDownList_SortBy.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("ExpenseName"), this.CurPageDataObj.DisplayName));                
            }
        }
        catch (Exception ex)
        {
            this.CurLogManager.LogError("[GonzalesMyClaims.SwitchLanguage.EX] : " + ex.Message, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.User);
        }

    }
    #endregion

    #region BuildTable
    public void BuildTable()
    {
        TableRow HeaderRow = new TableRow();

        for (int x = 0; x < this.TotalColumns; x++)
        {
            HeaderRow.Cells.Add(new TableCell());
            HeaderRow.Cells[x].CssClass = "GridViewHeader";
        }

        HeaderRow.Cells[0].Text = "Active"; HeaderRow.Cells[0].HorizontalAlign = HorizontalAlign.Center;
        HeaderRow.Cells[1].Text = this.Code1; HeaderRow.Cells[1].HorizontalAlign = HorizontalAlign.Center;
        HeaderRow.Cells[5].Text = "Per Diem"; HeaderRow.Cells[5].HorizontalAlign = HorizontalAlign.Center;
        HeaderRow.Cells[2].Text = this.ExpenseName; HeaderRow.Cells[2].HorizontalAlign = HorizontalAlign.Left;
        HeaderRow.Cells[3].Text = this.Category;  HeaderRow.Cells[3].HorizontalAlign = HorizontalAlign.Center;
        HeaderRow.Cells[4].Text = ""; HeaderRow.Cells[4].HorizontalAlign = HorizontalAlign.Center;

        this.Table_ClaimDetailGrid.Rows.Add(HeaderRow);
        
    }
    #endregion

    #region BuildRow

    public void BuildRow(DataRow ResultRow)
    {
        TableRow NewTableRow = new TableRow();
        NewTableRow.ID = ResultRow[this.CurPageDataObj.InternalID].ToString();

        for (int x = 0; x < this.TotalColumns; x++)
        {
            // set default setting to all the row
            NewTableRow.Cells.Add(new TableCell());
            NewTableRow.Cells[x].CssClass = "GridViewItem";
            NewTableRow.Cells[x].HorizontalAlign = HorizontalAlign.Center;
        }

        // Select indicator
        CheckBox CheckBoxSelected = new CheckBox();
        CheckBoxSelected.ID = NewTableRow.ID + "_CheckBoxSelected";

        NewTableRow.Cells[0].Controls.Add(CheckBoxSelected);
        NewTableRow.Cells[0].Width = new Unit(20);

        // Per diem indicator
        CheckBox CheckBoxPerDiem = new CheckBox();
        CheckBoxPerDiem.ID = NewTableRow.ID + "CheckBoxPerDiem";

        NewTableRow.Cells[5].Controls.Add(CheckBoxPerDiem);
        NewTableRow.Cells[5].Width = new Unit(20);
        //CheckBoxPerDiem.Checked = (ResultRow[this.CurPageDataObj.PerDiem].ToString().CompareTo("1") == 0);

        // code
        NewTableRow.Cells[1].Text = ResultRow[this.CurPageDataObj.Code].ToString();

        // description
        NewTableRow.Cells[2].Text = ResultRow[this.CurPageDataObj.DisplayName].ToString();
        NewTableRow.Cells[2].HorizontalAlign = HorizontalAlign.Left;

        // category
        DropDownList NewDropDownList_Category = new DropDownList();
        NewDropDownList_Category.ID = NewTableRow.ID + "_Category";
        NewDropDownList_Category.CssClass = "FormDropDown";
        NewDropDownList_Category.Width = Unit.Percentage(90);

        NewDropDownList_Category.Items.Add(new ListItem("", ""));
        NewDropDownList_Category.Items.Add(new ListItem(ClaimManager.GetClaimCategoryInString(CategoryOfClaim.General), "0"));
        NewDropDownList_Category.Items.Add(new ListItem(ClaimManager.GetClaimCategoryInString(CategoryOfClaim.Entertainment), "1"));
        // Thang Nguyen added 27/03/2013
        //NewDropDownList_Category.Items.Add(new ListItem(ClaimManager.GetClaimCategoryInString(CategoryOfClaim.PACEMarketingEvent), "2"));

        NewTableRow.Cells[3].Controls.Add(NewDropDownList_Category);
        NewTableRow.Cells[3].Width = Unit.Pixel(250);

        // delete --FRANK set for FA Manager
        if (this.CurrentPrivateSession.CurrentLoggedOnUser.IsFinanceAdmin)
        {
            if (this.CurrentPrivateSession.CurrentLoggedOnUser.IsFinancialManager)
            {
                LinkButton LinkButtonDelete = new LinkButton();
                LinkButtonDelete.ID = NewTableRow.ID + "_LinkButtonDelete";
                LinkButtonDelete.Text = this.DeleteLink;
                LinkButtonDelete.CssClass = "GridViewLink";
                LinkButtonDelete.Attributes["onclick"] = "return confirm ('" + this.ConfirmedMessage + "');";
                LinkButtonDelete.Click += new EventHandler(LinkButtonDelete_Click);

                NewTableRow.Cells[4].Controls.Add(LinkButtonDelete);
                NewTableRow.Cells[4].HorizontalAlign = HorizontalAlign.Center;
            }
        }
        

        this.Table_ClaimDetailGrid.Rows.Add(NewTableRow);
    }



    #endregion

    #region ShowErrorMessage
    protected void ShowErrorMessage(string ErrorMessage)
    {
        this.Table_MessageBox.Visible = true;
        this.Table_MessageBox.Rows[0].Cells[0].Text = ErrorMessage;
        this.Table_MessageBox.Rows[0].Cells[0].CssClass = "ErrorBox";
    }
    #endregion

    #region ShowMessage
    protected void ShowMessage(string Message)
    {
        this.Table_MessageBox.Visible = true;
        this.Table_MessageBox.Rows[0].Cells[0].Text = Message;
        this.Table_MessageBox.Rows[0].Cells[0].CssClass = "MessageBox";
    }
    #endregion

    #endregion

    #region Data Operation

    #region LoadData
    protected void LoadData()
    {
        using (GLClaimTypeManager CurClaimTypeManager = new GLClaimTypeManager(this.CurrentPrivateSession))
        {            
            
            MasterBaseCollection ResultObj = CurClaimTypeManager.GetAllClaimTypeInLang(this.CurrentPrivateSession.CurrentLoggedOnUser.PreferedLanguage);

            if (ResultObj != null)
            {
                this.ResultTable = new DataTable();
                ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.InternalID, Type.GetType("System.String")));
                ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.Code, Type.GetType("System.String")));
                ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.DisplayName, Type.GetType("System.String")));

                DataRow RowObj = null;

                for (int x = 0; x < ResultObj.Count; x++)
                {
                    GLClaimType CurGLClaimType = (GLClaimType)ResultObj[x];

                    RowObj = ResultTable.NewRow();

                    RowObj[this.CurPageDataObj.InternalID] = CurGLClaimType.InternalID;
                    RowObj[this.CurPageDataObj.Code] = CurGLClaimType.GLCode;
                    RowObj[this.CurPageDataObj.DisplayName] = CurGLClaimType.DisplayName;

                    ResultTable.Rows.Add(RowObj);
                }
            }
            else
            {
                this.CurLogManager.LogError("[GonzalesAdminExpenseCompanyListing.LoadData] : Failed at CurClaimTypeManager.GetActiveClaimTypeInLangByEntity] : " + CurClaimTypeManager.ErrorMessage, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.System);
            }
            
        }
    }
    #endregion    

    #region LoadDataBasedOnEntity
    protected void LoadDataBasedOnEntity()
    {
        using (GLClaimTypeManager CurClaimTypeManager = new GLClaimTypeManager(this.CurrentPrivateSession))
        {
            MasterBaseCollection ResultObj = CurClaimTypeManager.GetActiveClaimTypeInLangByEntity(this.CurrentPrivateSession.CurrentLoggedOnUser.PreferedLanguage, (new Entity(this.DropDownList_ByEntity.SelectedValue, this.DropDownList_ByEntity.SelectedItem.Text)));

            if (ResultObj != null)
            {
                for (int x = 1; x < this.Table_ClaimDetailGrid.Rows.Count; x++)
                {
                    for (int y = 0; y < ResultObj.Count; y++)
                    {
                        if (this.Table_ClaimDetailGrid.Rows[x].ID.CompareTo(ResultObj[y].InternalID) == 0)
                        {
                            GLClaimType CurClaimType = (GLClaimType)ResultObj[y];
                            DropDownList DropDownList_Category = (DropDownList)this.Table_ClaimDetailGrid.Rows[x].Cells[3].Controls[0];
                            DropDownList_Category.SelectedIndex = -1;
                            DropDownList_Category.SelectedValue = ClaimManager.GetClaimCategoryInCode(CurClaimType.Category).ToString();

                            ((CheckBox)this.Table_ClaimDetailGrid.Rows[x].Cells[0].Controls[0]).Checked = true;
                            ((CheckBox)this.Table_ClaimDetailGrid.Rows[x].Cells[5].Controls[0]).Checked = CurClaimType.PerDiem;
                            break;
                        }
                    }
                }
            }
            else
            {
                this.CurLogManager.LogError("[GonzalesAdminExpenseCompanyListing.LoadData] : Failed at CurClaimTypeManager.GetActiveClaimTypeInLangByEntity] : " + CurClaimTypeManager.ErrorMessage, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.System);
            }

        }
    }
    #endregion    

    #region ExpenseDetailCodeValidate

    protected bool ExpenseDetailCodeValidate()
    {
        bool found = false;

        for (int x = 1; x < this.Table_ClaimDetailGrid.Rows.Count; x++)
        {
            if (this.Table_ClaimDetailGrid.Rows[x].Cells[1].Text.CompareTo(this.TextBox_Code.Text) == 0)
            {
                found = true;
                break;
            }
        }

        return found;
    }

    #endregion

    #region DataSave

    protected bool DataSave()
    {
        bool smooth = true;

        if ((smooth = this.ExpenseDetailCodeValidate()))
        {
            using (GLClaimTypeManager CurManager = new GLClaimTypeManager(this.CurrentPrivateSession))
            {
                if (!(smooth = CurManager.AddNewClaimType(this.TextBox_Code.Text, this.TextBox_Description.Text)))
                {
                    string LogID = SwissArmy.UniqueID();
                    this.CurLogManager.LogError(LogID, "[GonzalesAdminExpenseCompanyListing.DataSave] : Failed at CurManager.AddNewClaimType('" + this.TextBox_Code.Text + "', '" + this.TextBox_Description.Text + "') : " + CurManager.ErrorMessage, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.System);
                    this.ShowErrorMessage(this.ErrorMessage + LogID);
                }
            }
        }
        else
        {
            this.ShowErrorMessage(this.InvalidMessage);
        }

        return smooth;
    }

    #endregion

    #endregion

    #region Class: DataObj

    protected class DataObj
    {
        public readonly string InternalID = "InternalID";
        public readonly string Code = "Code";
        public readonly string DisplayName = "DisplayName";
        public readonly string Category = "Category";
        public readonly string PerDiem = "PerDiem";
    }

    #endregion


}
